/*
 * =====================================================================================
 *
 *       Filename:  eliminate_space.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  12/09/2010 04:03:48 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ken), chen_kenz@emc.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include <iostream>
#include <cassert>

using namespace std;

char* eliminateSpace( char* str )
{
  assert( str != NULL );

  if( *str != '\0' )
  {
    eliminateSpace( str+1 );
  }

  if( *str  == ' ' )
  {
    for( int i = 0; *(str+i) != '\0'; ++i )
    {
      *(str+i) = *(str+i+1);
    }
  }

  return str;
}

int main( int argc, char* argv[] )
{
  char str[] = "a b c";
  cout << eliminateSpace(str) << "#" << endl; 

  char str1[] = "a b c d ";
  cout << eliminateSpace(str1) << "#" << endl; 

  char str2[] = " a b c  ";
  cout << eliminateSpace(str2) << "#" << endl; 

  char str3[] = "   ";
  cout << eliminateSpace(str3) << "#" << endl; 


  return 0;
}
